package org.csu.mypetstore.service;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.persistence.SignInDAO;
import org.csu.mypetstore.persistence.impl.SignInDAOImpl;

public class SignInService {
    private SignInDAO signInDAO;
    public SignInService(){
        signInDAO = new SignInDAOImpl();
    }
    public Account getAccount(String username) {
        return signInDAO.getAccountByUsername(username);
    }

    public Account getAccount(String username, String password) {
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        return signInDAO.getAccountByUsernameAndPassword(account);
    }

    public void insertAccount(Account account) {
        signInDAO.insertAccount(account);
        signInDAO.insertProfile(account);
        signInDAO.insertSignon(account);
    }

    public void updateAccount(Account account) {
        signInDAO.updateAccount(account);
        signInDAO.updateProfile(account);

        if (account.getPassword() != null && account.getPassword().length() > 0) {
            signInDAO.updateSignon(account);
        }
    }


}
